#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winsock2.h>
#include <MYSQL/mysql.h>

int main()
{
		WSADATA WSAData;
		SOCKET sock;
		MYSQL *mysql = NULL;
		MYSQL_RES *sql_user = NULL;
		MYSQL_ROW *sql_user_row = NULL;
		unsigned int nbr_champ = 0;
	printf("BlackWhite Server v1.0.0.1 \n");
	printf("Initialisation du socket ... \n");
	WSAStartup(MAKEWORD(2,0), &WSAData);
	sock = socket(AF_INET, SOCK_STREAM, 0);
	SOCKADDR_IN sin;
	sin.sin_addr.s_addr = htonl(INADDR_ANY);
	sin.sin_family = AF_INET;
	sin.sin_port = htons(5000);
	bind(sock, (SOCKADDR *) &sin, sizeof sin);
	listen(sock, 5);
	int taille = (int) sizeof(sin);
	accept(sock, (SOCKADDR *) &sin, &taille);
	printf("Socket initialise correctement !! \n");
	printf("Connection a la base de donnee ... \n");	
	mysql_init(&mysql);
	mysql_option(&mysql, MYSQL_READ_DEFAULT_GROUP, "option");
	mysql_real_connect(&mysql, "localhost", "blackwhite", "bwpassword", "database", 0, NULL, 0);
	mysql_query(&mysql, "SELECT * FROM user");
	sql_user = mysql_use_result(&mysql);
	nbr_champ = mysql_num_fields(sql_user);
	mysql_free_result(sql_user);
	mysql_close(&mysql);
	closesocket(sock);
	WSACleanup();
	printf("Socket ferme");
	while(1);
	return 0;
}